/*
 * Created on :Sep 10, 2012 Author :songlin.li
 */
package com.dmagic.cms.common.util;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * statistics service method spend time
 * 
 * @author songlin.li @ Version : V<Ver.No> <Sep 10, 2012>
 */
public class LogAspect {

    private Logger logger = Logger.getLogger(LogAspect.class);

    public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
        logger.info("$$$$$$$$$$$$$$$$$$$$$$$$Beginning method: " + joinPoint.toLongString());
        long startTime = System.currentTimeMillis();
        Object result;
        try {
            result = joinPoint.proceed();
        } finally {
            logger.info("$$$$$$$$$$$$$$$$$$$$$$$$Method " + joinPoint.toShortString() + " invocation time: "
                    + (System.currentTimeMillis() - startTime) + " ms.");
        }
        return result;
    }

}